package com.qwz.example.itreator.impl;

import com.qwz.example.itreator.Iterator;

/**
 * @author Qiuwuzhi
 * @version V1.0
 * @Description: 用来实现访问数组的迭代接口
 * @Package com.qwz.example.ArrayIteratorImpl
 * @date 2019/12/26 15:27
 */
public class ArrayIteratorImpl implements Iterator {
    /**
     * 用来存放被迭代的聚合对象
     */
    private SalaryManager aggregate;

    public ArrayIteratorImpl(SalaryManager aggregate) {
        this.aggregate = aggregate;
    }

    private int index = -1;

    public void first() {
        index = 0;
    }

    public void next() {
        if (index < this.aggregate.size()) {
            index += 1;
        }
    }

    public boolean isDone() {
        if (index == this.aggregate.size()) {
            return true;
        }
        return false;
    }

    public Object currentItem() {
        return this.aggregate.get(index);
    }
}
